﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace TransportMe
{
    public partial class Calculator : PhoneApplicationPage
    {
        public Calculator()
        {
            InitializeComponent();
            displayCalculations(30);//hardcoded
        }

        public void displayCalculations(double distance) {
            lblDistanceValue.Text = distance.ToString()+" km";
            lblFuelCostValue.Text = "$ "+CostCalculator.calculateFuelCostByDistance(Car.userCar, distance).ToString();
            lblCO2Value.Text = CostCalculator.calculateCarbonEmissionsByDistance(Car.userCar, distance).ToString()+" gCO2";

            //60 = avg speed of traveling cars
            double estimatedTimeNeeded = (distance / 60) * 60;
            lblEstTimeValue.Text = estimatedTimeNeeded.ToString() + "mins";

            double hourOfDay = (Convert.ToDouble(DateTime.Now.ToOADate()) * 24) % 24;
            double startParkingMinutes = hourOfDay * 60 + estimatedTimeNeeded;
            DateTime dt = new DateTime();
            dt.AddMinutes(startParkingMinutes);
            CarPark cp = CostCalculator.calculateNearestCarPark(Home.pinEnd.Location.Longitude, Home.pinEnd.Location.Latitude);
            double parkCost = CostCalculator.calculateCostOfParking(cp, dt);
            lblCarparkValue.Text = "$" + parkCost.ToString();

            double erpCost = CostCalculator.calculateERPCost(Home.listOfLoc , ERPRate.listOfERPRates);
            lblERPValue.Text = "$" + erpCost.ToString();
        }
    }
}